﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CuitWinCheckBoxTreeItem.cs" company="">
//   
// </copyright>
// <summary>
//   The cuit win check box tree item.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace UITest.CUIT.CuitControls.WinControls
{
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

    /// <summary>
    ///     The cuit win check box tree item.
    /// </summary>
    public class CuitWinCheckBoxTreeItem : CuitWinControl<WinCheckBoxTreeItem>
    {
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="CuitWinCheckBoxTreeItem" /> class.
        /// </summary>
        public CuitWinCheckBoxTreeItem()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCheckBoxTreeItem"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        public CuitWinCheckBoxTreeItem(UITestControl testControl)
            : base(testControl)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCheckBoxTreeItem"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinCheckBoxTreeItem(UITestControl testControl, string searchProperties)
            : base(testControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCheckBoxTreeItem"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinCheckBoxTreeItem(UITestControl testControl, string searchProperties, string filterProperties)
            : base(testControl, searchProperties, filterProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCheckBoxTreeItem"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinCheckBoxTreeItem(ICuitControlBase wrappedControl, string searchProperties)
            : base(wrappedControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCheckBoxTreeItem"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinCheckBoxTreeItem(
            ICuitControlBase wrappedControl, 
            string searchProperties, 
            string filterProperties)
            : base(wrappedControl, searchProperties, filterProperties)
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets or sets a value indicating whether checked.
        /// </summary>
        public bool Checked
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Checked;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether has child nodes.
        /// </summary>
        public bool HasChildNodes
        {
            get
            {
                this._control.WaitForControlReady();
                return this.UnWrap().HasChildNodes;
            }
        }

        /// <summary>
        ///     Gets or sets a value indicating whether indeterminate.
        /// </summary>
        public bool Indeterminate
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Indeterminate;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value.ToString());
                this._control.Indeterminate = value;
            }
        }

        /// <summary>
        ///     Gets the nodes.
        /// </summary>
        public UITestControlCollection Nodes
        {
            get
            {
                this._control.WaitForControlReady();
                return this.UnWrap().Nodes;
            }
        }

        /// <summary>
        ///     Gets the parent node.
        /// </summary>
        public UITestControl ParentNode
        {
            get
            {
                this._control.WaitForControlReady();
                return this.UnWrap().ParentNode;
            }
        }

        /// <summary>
        ///     Gets or sets a value indicating whether selected.
        /// </summary>
        public bool Selected
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Selected;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value.ToString());
                this._control.Selected = value;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     The check.
        /// </summary>
        public void Check()
        {
            this._control.WaitForControlReady();
            if (!this._control.Checked)
            {
                this._control.Checked = true;
            }

            this.WriteTestOutput(string.Empty);
        }

        /// <summary>
        ///     The select.
        /// </summary>
        public void Select()
        {
            this._control.WaitForControlReady();
            if (!this._control.Selected)
            {
                this._control.Selected = true;
            }

            this.WriteTestOutput(string.Empty);
        }

        /// <summary>
        ///     The un check.
        /// </summary>
        public void UnCheck()
        {
            this._control.WaitForControlReady();
            if (this._control.Checked)
            {
                this._control.Checked = false;
            }

            this.WriteTestOutput(string.Empty);
        }

        /// <summary>
        ///     The un select.
        /// </summary>
        public void UnSelect()
        {
            this._control.WaitForControlReady();
            if (!this._control.Selected)
            {
                this._control.Selected = false;
            }

            this.WriteTestOutput(string.Empty);
        }

        #endregion
    }
}